﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyPush
{
    public partial class HashSetForm : Form
    {
        public HashSet<string> Hashs { get; private set; }
        public HashSetForm(HashSet<string> hashs)
        {
            InitializeComponent();
            this.Hashs = hashs;
        }

        private void HashSetForm_Load(object sender, EventArgs e)
        {
            if (this.Hashs == null)
                this.Hashs = new HashSet<string>();
            foreach (string hash in this.Hashs)
            {
                listBoxMain.Items.Add(hash);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            string hash = tValue.Text;
            if (string.IsNullOrEmpty(hash) || this.Hashs.Contains(hash))
            {
                MessageBox.Show("值无效，请重新输入！", "提示");
                return;
            }
            this.Hashs.Add(hash);
            listBoxMain.Items.Add(hash);
            tValue.Text = null;
        }

        private void menuBtnDelete_Click(object sender, EventArgs e)
        {
            if (listBoxMain.SelectedItem != null)
            {
                string hash = listBoxMain.SelectedItem.ToString();
                this.Hashs.Remove(hash);
                listBoxMain.Items.Remove(hash);
            }
        }
    }
}
